<?php

namespace app\index\controller\decorator;

use think\Controller;
use think\Request;
use app\index\controller\tan\Eliminate;
class Cardbalancelog extends Controller implements Decoratorinterface
{
    private $data='';
    private $rule=[
        "user_id"=>"require|number",
        "before_balance"=>"require|float",
        "money"=>"require|float",
        "after_balance"=>"require|float",
        "types"=>"max:2",
        "operating"=>"require|in:0,1",
        "state"=>"require|in:0,1",
        "createtime"=>"require|dateFormat:Y-m-d",
        "batchcode"=>"require|max:32",
        "out_trade_no"=>"require|max:32",
        "description"=>"max:255",
        "remark"=>"max:255",
    ];
    public function __construct(array $data) {
        parent::__construct();
        $this->data=$data;
    }
    
    public function after(): bool {
        $S_t=$this->validate($this->data, $this->rule);
        if($S_t !== true){
            echo $S_t;
            return false;
        }
        $d= \think\Db::table("card_balance_log")->insert($this->data);
        return (bool)$d;        
    }

    public function before() {
        $this->data= Eliminate::E($this->data, $this->rule);
    }

}
